package com.bpms.common;

import java.io.FileOutputStream;
import java.io.OutputStream;

import com.bpms.common.CommonUtil;
import com.bpms.common.JdbcWorker;
import com.bpms.common.VO;
import com.bpms.common.VOList;
import com.bpms.esb.SV;
import com.bpms.report.CommonGenReport;

public class Testccc {
	public static void main(String[] args) {
		try{			
			String sql = "select * from cm_djb";
			
			String realpath="";
			String reportfile="";
			VOList vol = loadData(sql);
			
			byte[] buffer = genHDReport(vol, realpath, reportfile);		
			
			OutputStream os = new FileOutputStream("e:/bankReport.pdf");
			os.write(buffer);
			os.close();
		}catch(Exception e){
			CommonUtil.debug("ShowImage.showpic exception", e);
		}
	}

	private static byte[] genHDReport(VOList vol, String realpath, String reportfile) {
		
		VO vd = new VO();
		vd.setObj("volist", vol);
		VO vr =  SV.g("report.hdprintreport", vd);			
		CommonUtil.debug("vo return from report.hdprintreport is " + (VO)((VOList)vr.getObj("list")).listData.get(0));
		
		VO p = new VO();
		p.setAttr("path", reportfile);
		CommonGenReport cgr = new CommonGenReport();
		byte[] buffer = cgr.genPdfReport(p, vr,realpath);
		CommonUtil.debug("genpdfreport pdf file size " + buffer.length);
		return buffer;
	}
	
	private static VOList loadData(String sql) {
		try
        {
			JdbcWorker j = new JdbcWorker();
			VOList vol = j.readAll(new VO(), sql);
			CommonUtil.debug("volist is " + vol + " volist count:"+ vol.rowCount);
			return vol;
        }
        catch(Exception e)
        {
            CommonUtil.debug("ShowReport exception", e);
        }
        return null;
	}
}
